<?php
class CustomControllerAction extends Zend_Controller_Action {
	public $db;
	public $breadcrumbs;
	public $messager;
	
	public function init() {
		$this->db = Zend_Registry::get('db');
		
		$this->breadcrumbs = new Breadcrumbs();
		$this->breadcrumbs->addStep('首页', '/');
		
		$this->messager = $this->_helper->getHelper('FlashMessenger');
	}
	
	public function preDispatch() {
		$auth = Zend_Auth::getInstance();
		if ($auth->hasIdentity()) {
			$this->view->authenticated = true;
			$this->view->identity = $auth->getIdentity();
		} else {
			$this->view->authenticated = false;
		}
	}
	
	public function postDispatch() {
		$this->view->breadcrumbs = $this->breadcrumbs;
		$this->view->title = $this->breadcrumbs->getTitle();
		
		$this->view->messages = $this->messager->getMessages();
	}
	
	public function getUrl($action = null, $controller = null) {
		$url = rtrim($this->getRequest()->getBaseUrl(), '/').'/';
		$url .= $this->_helper->url->simple($action, $controller);
		
		return '/'.ltrim($url, '/');
	}
	
	public function getCustomUrl($options, $route = null) {
		return $this->_helper->url->url($options, $route);
	}
}
?>